package com.yuchuang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuchuang.base.PageInfo;
import com.yuchuang.mapper.SpecMapper;
import com.yuchuang.model.Spec;
import com.yuchuang.model.vo.SpecVo;
import com.yuchuang.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author:cy Date: 2023-06-16-13:14
 * Description:
 */
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements SpecService {
    @Autowired
    private SpecMapper specMapper;
    @Override
    public List<Spec> queryAll(HttpServletRequest request){
        QueryWrapper<Spec> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(request.getParameter("specName") != null,"spec_name",request.getParameter("specName"));
        List<Spec> list = specMapper.queryAllImplBatis(queryWrapper);
        return list;
    }
    @Override
    public PageInfo selectPageVo(SpecVo specVo){
        Page<Spec> page = new Page<>(specVo.getPageNum(),specVo.getPageSize());
        QueryWrapper<Spec> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(specVo.getSpecName() != null,"spec_name",specVo.getSpecName());
        IPage<Spec> result = specMapper.selectPageVoMapper(page,queryWrapper);
        int pageNums =(int) result.getPages();
        int size =(int) result.getSize();
        int pageNum =(int) result.getCurrent();
        int total =(int) result.getTotal();
        List t = result.getRecords();
        return new PageInfo().setContent(t).setPage(pageNum).setSize(size).setTotal(total).setPages(pageNums);
    }
    @Override
    public int insert(Spec spec){
        int val = specMapper.insertImplBatis(spec);
        return val;
    }
    @Override
    public int update(Map<String,Object> params){
        int val = specMapper.updateImplBatis(params);
        return val;
    }
    @Override
    public int delete(Map<String,Object> params){
        int val = specMapper.deleteImplBatis(params);
        return val;
    }
}
